/*
 *  Copyright (c)  2016-NOW  Jacars Co.Ltd.
 *  All rights reserved.
 */
package com.jacars.biz.user.dao.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jacars.biz.user.dao.model.JsptPost;
import com.jacars.biz.user.dao.service.JsptPostService;
import com.jacars.biz.user.dao.mapper.JsptPostMapper;
import com.jacars.common.utils.FuncUtil;
import com.jacars.biz.user.vo.JsptPostVO;
import com.jacars.common.service.impl.SuperServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 岗位表 服务实现类
 *
 * @author Chill
 */
@Service
public class JsptPostServiceImpl extends SuperServiceImpl<JsptPostMapper, JsptPost> implements JsptPostService {

	@Override
	public IPage<JsptPostVO> selectPostPage(IPage<JsptPostVO> page, JsptPostVO post) {
		return page.setRecords(baseMapper.selectPostPage(page, post));
	}

	@Override
	public String getPostIds(String tenantId, String postNames) {
		List<JsptPost> postList = baseMapper.selectList(Wrappers.<JsptPost>query().lambda().eq(JsptPost::getTenantId, tenantId).in(JsptPost::getPostName, FuncUtil.toStrList(postNames)));
		if (postList != null && postList.size() > 0) {
			return postList.stream().map(post -> FuncUtil.toStr(post.getId())).distinct().collect(Collectors.joining(","));
		}
		return null;
	}

	@Override
	public List<String> getPostNames(String postIds) {
		return baseMapper.getPostNames(FuncUtil.toLongArray(postIds));
	}

}
